@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('admin.userLevel.index') }}">等级列表</a></li>
                                <li class="breadcrumb-item active" aria-current="page">新增编辑</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="row">
                                    <div class="col-lg-5">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>等级名称：</label>
                                                <input type="text" class="form-control" id="title" value="{{ $detail->title ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>等级图标：</label>
                                                <input type="file" class="form-control" id="image" onchange="upload_image()">
                                                <input type="hidden" id="image-value" value="{{ $detail->icon ?? '' }}">
                                                <a href="javascript:void(0);" id="show-image" style="display: none;" target="_blank">查看图片</a>
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>充值金额：</label>
                                                <input type="text" class="form-control" id="need_money" value="{{ $detail->need_money ?? 0 }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>奖励最低金额：</label>
                                                <input type="text" class="form-control" id="min_money" value="{{ $detail->min_money ?? 0 }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>乐游币比例：</label>
                                                <input type="text" class="form-control" id="ly_rate" value="{{ $detail->ly_rate ?? 0 }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>积分比例：</label>
                                                <input type="text" class="form-control" id="integral_rate" value="{{ $detail->integral_rate ?? 0 }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>节日福利：</label>
                                                <input type="text" class="form-control" id="jr_gift" value="{{ $detail->jr_gift ?? '无' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>专属客服福利：</label>
                                                <input type="text" class="form-control" id="zskf_gift" value="{{ $detail->zskf_gift ?? '无' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>每5日领取玩服积分：</label>
                                                <input type="text" class="form-control" id="day_reward" value="{{ $detail->day_reward ?? 0 }}">
                                            </div>
                                        </div>

                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <button class="btn btn-primary" onclick="operation_tip2({{$detail->id ?? 0}})">提交</button>
                                            </div>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        let isLoading = false;

        //提交
        function submit(id) {

            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{ route('admin.userLevel.update','').'/' }}' + id + '', {
                    title: $('#title').val(),
                    icon: $('#image-value').val(),
                    need_money: $('#need_money').val(),
                    ly_rate: $('#ly_rate').val(),
                    integral_rate: $('#integral_rate').val(),
                    min_money: $('#min_money').val(),
                    jr_gift: $('#jr_gift').val(),
                    zskf_gift: $('#zskf_gift').val(),
                    day_reward: $('#day_reward').val(),
                })
                    .then(function (response) {
                        isLoading = false;
                        toast(response.data.message);
                        if (response.data.success === 'true') {
                            setTimeout(() => {
                                window.location.href='{{ route('admin.userLevel.index') }}';
                            }, 2000)
                        }
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }

        function upload_image() {
            var formData = new FormData();
            formData.append('file', $('#image')[0].files[0]);  //添加图片信息的参数
            $.ajax({
                url: "{{route('admin.games.uploadImg', '')}}",
                type: "post",
                dataType: "json",
                cache: false,
                data: formData,
                processData: false,// 不处理数据
                contentType: false, // 不设置内容类型
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function (data) {
                    if (data.status === 0) {
                        $('#show-image').attr('href', '/uploads/' + data.path)
                        $('#image-value').val('/uploads/' + data.path)
                        $('#show-image').css('display', 'inline-block')
                        toast("添加成功");
                    }
                }
            })
        }
    </script>
    </body>

@endsection
